package org.rambadger.command.listeners;

import org.axonframework.eventhandling.annotation.EventHandler;
import org.axonframework.eventhandling.replay.ReplayAware;
import org.mongojack.JacksonDBCollection;
import org.rambadger.command.event.PlatformCreated;
import org.rambadger.command.representation.Platform;


public class PlatformListener implements ReplayAware {
    JacksonDBCollection<Platform, String> platforms;

    public PlatformListener(JacksonDBCollection<Platform, String> platforms) {
        this.platforms = platforms;
    }

    @Override
    public void beforeReplay() {
        platforms.drop();
    }

    @Override
    public void afterReplay() {}

    @EventHandler void on(PlatformCreated event) {
        platforms.insert(new Platform(event.getPlatformId(), event.getPlatformName(), event.getDescription()));
    }
}
